
var templateFactory = new templateFactory()
function templateFactory(){
	var template = "";
	var data = null;
    this.setData=template_setData
    this.setTemplate=template_setTemplate
    this.getListParameter=template_getListParameter
	function template_setData(dt){
		data = dt;
	}
	function template_setTemplate(id){
		template = document.getElementById(id).innerHTML;
	}
	function template_getListParameter(){
		var arr = template.split("{");
		var newHTML = template;
		for(var i=1;i<arr.length;i++){
			var arr1 =  arr[i].split("}");
			var stm = arr1[0].split(" ");
			if(stm[0] == "loop"){
				var htmlLoop = loopView(stm[1],stm[2]);
				newHTML = newHTML.replace('{'+arr1[0]+'}',htmlLoop);
			}else{
				newHTML = newHTML.replace('{'+arr1[0]+'}',data[arr1[0]]);
			}
		}
		return newHTML;
	}
	function loopView(dataFill,id){
		var html = document.getElementById(id).innerHTML;
		var rtHTML = "";
		var listCol = data[dataFill];
		for(var i=0;i<listCol.length;i++){
			var newHTML = html;
			var arr = html.split("{");		
			for(var ii=1;ii<arr.length;ii++){
				var arr1 =  arr[ii].split("}");
				newHTML = newHTML.replace('{'+arr1[0]+'}',listCol[i][arr1[0]]);
			}
			rtHTML += newHTML; 
		}
		return rtHTML;
	}
}